package org.sgx.gapigui.client.ui.editableModels.pagespeed;

import org.sgx.gapi.client.apis.pagespeed.PageSpeedResultPageStats;
import org.sgx.gwteditors.client.impl1.edbean.EditableBean;

import com.google.gwt.core.shared.GWT;

public abstract class PageStats implements EditableBean {
	Integer numberResources,numberHosts, totalRequestBytes, numberStaticResources, htmlResponseBytes, 
	cssResponseBytes, imageResponseBytes, javascriptResponseBytes, otherResponseBytes, 
	numberJsResources, numberCssResources;

	public Integer getNumberResources() {
		return numberResources;
	}

	public void setNumberResources(Integer numberResources) {
		this.numberResources = numberResources;
	}

	public Integer getNumberHosts() {
		return numberHosts;
	}

	public void setNumberHosts(Integer numberHosts) {
		this.numberHosts = numberHosts;
	}

	public Integer getTotalRequestBytes() {
		return totalRequestBytes;
	}

	public void setTotalRequestBytes(Integer totalRequestBytes) {
		this.totalRequestBytes = totalRequestBytes;
	}

	public Integer getNumberStaticResources() {
		return numberStaticResources;
	}

	public void setNumberStaticResources(Integer numberStaticResources) {
		this.numberStaticResources = numberStaticResources;
	}

	public Integer getHtmlResponseBytes() {
		return htmlResponseBytes;
	}

	public void setHtmlResponseBytes(Integer htmlResponseBytes) {
		this.htmlResponseBytes = htmlResponseBytes;
	}

	public Integer getCssResponseBytes() {
		return cssResponseBytes;
	}

	public void setCssResponseBytes(Integer cssResponseBytes) {
		this.cssResponseBytes = cssResponseBytes;
	}

	public Integer getImageResponseBytes() {
		return imageResponseBytes;
	}

	public void setImageResponseBytes(Integer imageResponseBytes) {
		this.imageResponseBytes = imageResponseBytes;
	}

	public Integer getJavascriptResponseBytes() {
		return javascriptResponseBytes;
	}

	public void setJavascriptResponseBytes(Integer javascriptResponseBytes) {
		this.javascriptResponseBytes = javascriptResponseBytes;
	}

	public Integer getOtherResponseBytes() {
		return otherResponseBytes;
	}

	public void setOtherResponseBytes(Integer otherResponseBytes) {
		this.otherResponseBytes = otherResponseBytes;
	}

	public Integer getNumberJsResources() {
		return numberJsResources;
	}

	public void setNumberJsResources(Integer numberJsResources) {
		this.numberJsResources = numberJsResources;
	}

	public Integer getNumberCssResources() {
		return numberCssResources;
	}

	public void setNumberCssResources(Integer numberCssResources) {
		this.numberCssResources = numberCssResources;
	}

	public static PageStats from(PageSpeedResultPageStats p) {
		PageStats o = GWT.create(PageStats.class); 
		o.setCssResponseBytes(toInt(p.cssResponseBytes())); 
		o.setHtmlResponseBytes(toInt(p.htmlResponseBytes())); 
		o.setImageResponseBytes(toInt(p.imageResponseBytes())); 
		o.setJavascriptResponseBytes(toInt(p.javascriptResponseBytes()));
		o.setNumberCssResources(toInt(p.numberCssResources()));
		o.setNumberJsResources(toInt(p.numberJsResources())); 
		o.setNumberHosts(toInt(p.numberHosts())); 
		o.setNumberResources(toInt(p.numberResources())); 
		o.setNumberJsResources(toInt(p.numberJsResources())); 
		o.setNumberStaticResources(toInt(p.numberStaticResources())); 
		o.setOtherResponseBytes(toInt(p.otherResponseBytes())); 
		o.setTotalRequestBytes(toInt(p.totalRequestBytes())); 
		return o;
	}  
	static Integer toInt(String s) {
		try {
			return Integer.parseInt(s); 
		} catch (Exception e) {
			return 0;
		}
	}
	

}
